package com.wzxl.config.adapter;

import com.wzxl.config.filter.ApiFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author rxbyes
 * @version V1.0
 * @description: TODO ( 设置静态资源读取位置 )
 * @date 2017 下午3:03
 */
@Configuration
public class SpringBootMvcConfigurationAdapter extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry
                .addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

        registry
                .addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");

        registry
                .addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new ApiFilter()).addPathPatterns("/**");

        super.addInterceptors(registry);
    }
}
